﻿using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using FishEyeWPF;
using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.Wpf.Samples.BaseLibrary;

namespace CrazyAppBarWPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();


            this.Loaded += (s, e) =>
                {
                    GlassEffectHelper.EnableGlassEffect(this);

                    AddApplication(@"C:\Windows\System32\Notepad.exe");
                    AddApplication(@"C:\Windows\System32\xpsrchvw.exe");
                    AddApplication(@"C:\Windows\System32\Calc.exe");
                    AddApplication(@"C:\Windows\System32\Notepad.exe");
                    AddApplication(@"C:\Windows\System32\xpsrchvw.exe");
                    AddApplication(@"C:\Windows\System32\Calc.exe");
                    AddApplication(@"C:\Windows\System32\Notepad.exe");
                    AddApplication(@"C:\Windows\System32\xpsrchvw.exe");
                    AddApplication(@"C:\Windows\System32\Calc.exe");
                    AddApplication(@"C:\Windows\System32\Notepad.exe");
                    AddApplication(@"C:\Windows\System32\xpsrchvw.exe");
                    AddApplication(@"C:\Windows\System32\Calc.exe");
                    
                    this.Width = Programms.Width * 1.5;
                };
        }

        private void AddApplication(string path)
        {
            // Get Icon
            ShellFile sf = ShellFile.FromFilePath(path);
            BitmapSource bi = sf.Thumbnail.BitmapSource;

            Image image = new Image();
            image.VerticalAlignment = System.Windows.VerticalAlignment.Bottom;
            image.Source = bi;
            image.Tag = path;
            image.Width = 64;
            image.Height = 64;
            image.MouseLeftButtonDown += (s, e) =>
                {
                    Image i = s as Image;
                    //MessageBox.Show(i.Tag + " clicked");

                    Process p = new Process();
                    p.StartInfo.FileName = i.Tag.ToString();
                    p.Start();
                };
            image.Loaded += (s, e) =>
                {
                    Image i = s as Image;
                    FishEyeBehavior feb = new FishEyeBehavior();
                    var behaviors = System.Windows.Interactivity.Interaction.GetBehaviors(i);
                    behaviors.Add(feb);
                };

            Programms.Children.Add(image);

            
        }
    }
}
